module.exports = {
  /**
   * 获取招商邀请码列表
   * @url user/kh/getUserList 前端调用的url参数地址
   */
	main: async (event) => {
		let { data = {},userInfo,  util, originalParam } = event;
		let { uniID, pubFun, vk , db, _ } = util;
		let res = {code : -1, msg : ''};
	  // 业务逻辑开始----------------------------------------------------------- 
		// 可写与数据库的交互逻辑等等
		let {pageNum, pageSize} = data;
		// 仅限以下表允许不登录查看
		let dbName = 'vk-chaingood'
		let whereJson = {};
		let sortArr = [];
		// 指定返回字段开始-----------------------------------------------------------
		// 指定返回字段开始-----------------------------------------------------------
		// 排序规则开始-----------------------------------------------------------
		sortArr.push({
			"name":"_add_time",
			"type":"desc"
		});
		// 查询条件结束-----------------------------------------------------------
		res = await vk.baseDao.select({
			dbName:dbName,
			pageKey:true,
			getCount: true,
			pageIndex:pageNum || 1,
			pageSize:pageSize || 100,
			whereJson:whereJson,
			sortArr:sortArr
		}, util);
    if(res.total > pageSize) {
      let count = res.total / pageSize + 1
      let arr = []
      for (let i = 0; i < count; i++) {
        let info = await vk.baseDao.select({
        	dbName:dbName,
        	pageKey:true,
        	getCount: true,
        	pageIndex: i+1,
        	pageSize:pageSize,
        	whereJson:whereJson,
        	sortArr:sortArr
        }, util);
        arr = arr.concat(info.rows)
      }
      return {
        code: 0,
        msg: '查询成功',
        rows: arr,
        total: res.total
      }
    } else {
      return res;
    }
    
	  // 业务逻辑结束-----------------------------------------------------------
	}

}
